# Replication file for "Targeting, Accountability and Capture in Development Projects"
# Matthew S. Winters (University of Illinois at Urbana-Champaign 
# mwinters@illinois.edu 
# January 2013 

# This file reproduces Figure 1 in a PDF file

library(foreign)

capture.data <- read.dta("Capture_Replication_January2013.dta", convert.underscore = TRUE, convert.factors=FALSE)
attach(capture.data)

# Bar Plot of Capture Levels by Targeting -- Ordered by Proportion

target.type <- c("One City", "Multiple\nCities", "One Region", "Multiple\nRegions",
    "Rural Sector", "Urban Sector", "Social Group", "Business\nor Industry", "National")
    
target.mat <- matrix(NA, nrow=9, ncol=2, 
    dimnames=list(target.type, c("Capture", "No Capture")))
for (i in 1:9){
 target.mat[i,1] <- sum(capture[target==i]==1, na.rm=T)
 target.mat[i,2] <- sum(capture[target==i]==0, na.rm=T)
}

pct.capture.vec.3 <- target.mat[,1]/(target.mat[,1] + target.mat[,2])
o.temp.3 <- order(pct.capture.vec.3)
x.vals <- barplot(t(target.mat[o.temp.3,]))

pdf("CaptureTargetOrder.pdf", height=4, width=4)
par(mgp=c(1.5,.5,0)) #space between axis title, axes labels and axis line
par(mar=c(4,2.5,2,1)+0.1)
barplot(t(target.mat[o.temp.3,]), ylim=c(0,200),
 horiz=F, las=1, main="Capture Across Levels of Targeting",
 ylab="Number of Projects", axisnames=F,
 cex.main=0.75, cex.axis=0.66, cex.lab=0.66, cex.names=0.5)
axis(1, at=x.vals, lab=F, cex.axis=0.75, tick=F)
text(x.vals, par("usr")[3] - 7.5, label=target.type[o.temp.3], srt=55, adj=1, xpd=T, cex=.66)
legend("topleft", c("Capture", "No Capture"), fill=c("lightgrey","darkgrey"), 
 cex=.66, inset=.1)
text(x.vals, c(75, 30, 75, 50, 130, 130, 75, 50, 30), 
 round(pct.capture.vec.3[o.temp.3], digits=2), cex=.75)
dev.off()

# END OF FILE
